﻿using Mengsk.ProxyDelivery.Service;
using Seagull.BarTender.Print;
using System;
using System.Collections.Generic;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Mengsk.ProxyDelivery.App.UI.Config
{
    /// <summary>
    /// PrintDeviceConfigUserControl.xaml 的交互逻辑
    /// </summary>
    public partial class PrintDeviceConfigUserControl : UserControl, IPlugin
    {
        public string Title
        {
            get { return "热敏打印"; }
        }

        public Control UIControl
        {
            get { return this; }
        }

        public PrintDeviceConfigUserControl()
        {
            InitializeComponent();
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                LocalConfigService.UpdateValue("APP_NORMALPRINTER", this.cbbNormalPrinter.Text.Trim());
                LocalConfigService.UpdateValue("APP_HOTPRINTER", this.cbbDevices.Text.Trim());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                string[] printers = PrinterSettings.InstalledPrinters.OfType<string>().ToArray();
                this.cbbDevices.ItemsSource = printers;
                this.cbbNormalPrinter.ItemsSource = printers;
                this.cbbDevices.SelectedItem = LocalConfigService.GetValue("APP_HOTPRINTER", "");
                this.cbbNormalPrinter.SelectedItem = LocalConfigService.GetValue("APP_NORMALPRINTER", "");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }


    }
}
